package com.yunao.web.handler;

import com.yunao.commons.Exception.UserLoginException;
import com.yunao.commons.Exception.YunaoException;
import com.yunao.commons.enums.ResultEnum;
import com.yunao.commons.utils.ResultVOUtil;
import com.yunao.commons.vo.ResultVO;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

@ControllerAdvice
public class RuntimeExceptionHandler{

    @ExceptionHandler(RuntimeException.class)
    @ResponseBody
    @ResponseStatus(HttpStatus.FORBIDDEN)
    public ResultVO handle(RuntimeException e){
//        return ResponseVoUtils.error(ResponseEnum.EORROR,e.getMessage());
        return ResultVOUtil.error(ResultEnum.EORROR.getCode(),e.getMessage());
    }

    @ExceptionHandler(YunaoException.class)
    @ResponseBody
    public ResultVO handle(YunaoException e){
//        return ResponseVoUtils.error(ResponseEnum.EORROR,e.getMessage());
        return ResultVOUtil.error(ResultEnum.INNER_ERROR.getCode(),e.getMessage());
    }

    @ExceptionHandler(UserLoginException.class)
    @ResponseBody
    @ResponseStatus(HttpStatus.FORBIDDEN)
    public ResultVO handle(UserLoginException e){
        return ResultVOUtil.error(ResultEnum.TOKEN_ERROR);
    }

}
